const state = [{
	status: 0,
	name: '待付款',
	icon: 'pay',
	color: '#dd524d'
}, {
	status: 1,
	name: '待发货',
	icon: 'receipt',
	color: '#f0ad4e'
}, {
	status: 2,
	name: '待收货',
	icon: 'logistics',
	color: '#4cd964'
}, {
	status: 3,
	name: '待评价',
	icon: 'prize',
	color: '#007aff'
}, {
	status: 4,
	name: '已评价',
	icon: 'prize',
	color: '#8b00d1'
}, {
	status: 5,
	name: '已退款',
	icon: 'prize',
	color: '#666'
}]

const status = [{
	state: 1,
	color: '#4cd964',
	text: '可用'
}, {
	state: 0,
	color: '#dd524d',
	text: '已核销'
}]

export default {
	/**
	 * 订单状态对象
	 * @param {Object} e
	 */
	allState() {
		return state
	},
	hasState(e) {
		return state.find(item => item.status === e)
	},
	/**
	 * 状态
	 */
	filterStatus(e) {
		return status.find(item => item.state === e)
	},
	/**
	 * 获取今天
	 */
	hasToday() {
		let today = new Date()
		return today.toISOString().split('T')[0]
	},
	/**
	 * 昨天
	 */
	hasLastDay() {
		let today = new Date()
		let last = new Date(today.setDate(today.getDate() - 1))
		return last.toISOString().split('T')[0]
	},
	/**
	 * 本周
	 */
	hasWeekDay() {
		let today = new Date()
		let firstDayOfWeek = new Date(today.setDate(today.getDate() - today.getDay()))
		let lastDayOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6))
		return [firstDayOfWeek.toISOString().split('T')[0], lastDayOfWeek.toISOString().split('T')[0]]
	},
	/**
	 * 本月
	 */
	hasMonthDay() {
		let today = new Date()
		today.setDate(1)
		let firstDayOfMonth = today.toISOString().split('T')[0]
		let lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 1)
		let lastDayOfMonth = lastDay.toISOString().split('T')[0]
		return [firstDayOfMonth, lastDayOfMonth]
	},
	/**
	 * 关键字隐私
	 */
	zipStr(e) {
		if (!e) {
			return ''
		}
		let symbol = '*';
		if (e.length === 11) {
			return e.replace(/(\d{3})\d{4}(\d{2})/, `$1${symbol}${symbol}${symbol}${symbol}$2`)
		} else if (e.length === 18 || e.length === 15) {
			return e.replace(/(\d{12}).*/, `$1${symbol}${symbol}${symbol}${symbol}`)
		} else if (e.length === 2) {
			return e.charAt(0) + "*"
		} else {
			return e.charAt(0) + "*" + e.charAt(e.length - 1);
		}
	},
	/**
	 * 计算时间差
	 * (参数时间 - 当前时间) = 返回秒数
	 */
	zipCalcTimer(timer) {
		let timestamp = new Date(timer).getTime();
		var curstamp = Date.parse(new Date());
		return Math.ceil((timestamp - curstamp) / 1000)
	}
}